<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试机申请</title>
<import file="js.My97DatePicker.WdatePicker" />
<import file="js.jquery" />
<import type="css" file="css.workform" />
</head>

<body>
<form action="__URL__/apply_insert" method="post" name="form1" onsubmit="return CheckForm();">
  <div style="width: 725px;margin: 0 auto;text-align: right;padding-bottom: 10px">
    <span style="width:725px;text-align:right;">直属销售: <input type="text" size="10" name="higher" class="BigInput apply" value="{$data['higher']}"></span>
  </div>
  <table align="center" border="0" width="725" cellpadding="2" cellspacing="1" align="center" bgcolor="#000000" class="TableBlock">
    <tr>
    	<td class="TableContent">申请人</td>
    	<td class="TableData"><input type="text" name="apply_username" size="23" class="BigInpu apply" value="{$data['apply_username']}" ></td>
    	<td class="TableContent">申请日期</td>
    	<td class="TableData"><input type="text" name="apply_date" size="23" class="BigInpu apply" onClick="WdatePicker()" value="{$data.apply_date}" ></td>
    </tr>
    <tr>
     <td nowrap class="TableContent"> 设备类型：</td>
      <td class="TableData" nowrap colspan="3">
        <input type="radio" name="type" value="1" <if condition="$data['type'] eq '1'">checked</if> >统一安全管理与综合审计系统&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="type" value="2" <if condition="$data['type'] eq '2'">checked</if> >数据库审计系统
      </td>
    </tr>
    <tr>
     <td nowrap class="TableContent"> 产品型号：</td>
      <td class="TableData" nowrap colspan="3">
        <select name="model" style="width: 180px;" class="apply">
      		
      	</select>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 功能需求：</td>
      <td class="TableData" colspan="3">
        <textarea rows="4" cols="50" name="demand">{$data.demand}</textarea>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 客户名称：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="client_name" size="64" value="{$data.client_name}" class="BigInput apply" >
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 合作伙伴：</td>
      <td class="TableData" colspan="3">
      	<textarea rows="4" cols="50" name="partner" >{$data.partner}</textarea>
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 测试地点：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="place" size="40" value="{$data.place}" class="BigInput apply" >
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 预计归还时间：</td>
      <td class="TableData" colspan="3">
        <input type="text" name="back_time" size="23" class="BigInput apply" value="{$data.back_time}" onClick="WdatePicker()" >&nbsp;&nbsp;共计借测&nbsp;&nbsp;<input type="text" name="back_weekly" size="4" value="{$data.back_weekly}" class="BigInput apply" >&nbsp;&nbsp;周
      </td>
    </tr>
    <tr>
      <td nowrap class="TableContent"> 申请原因：</td>
      <td class="TableData" colspan="3">
        <textarea rows="4" cols="50" name="reason" >{$data.reason}</textarea>
      </td>
    </tr>
    <tr class="TableControl">
      <td nowrap colspan="4" align="center">
      	<input type="hidden" value="{$action}" name="action" >
      	<input type="hidden" value="{$data.id}" name="id" >
      	<input type="hidden" value="{$data.status}" name="status" >
      	<input type="hidden" value="{$data.dept_id}" name="dept_id" >
      	<input type="hidden" value="1" name="way" >
        <input type="submit" value="保存" onclick="changeway(1)" class="BigButton">&nbsp;&nbsp;&nbsp;
        <input type="submit" value="提交" onclick="changeway(2)" class="BigButton">&nbsp;&nbsp;&nbsp;
      </td>
    </tr>
    </table>
</form>

</body>
<script type="text/javascript">
	$(document).ready(function(){
		$("input[name='type']:radio").change(function(){
			checkradio();
		});
		checkradio();
	});
	function changeway(value){
		$("input[name='way']").val(value);
	}
	
	function checkradio(){
		var type = $("input[name='type']:radio:checked").val();
		if(type == undefined){
			return false;
		}
		var model = "{$data.model}";
		$.getJSON("__APP__/Device/gettype?type="+type,function(result){
			$("select[name='model'] option").remove();
			$.each(result, function(i,value){
				if(value.id == model){
					$("select[name='model']").append("<option value='"+value.id+"' selected>"+value.name);
				}else{
					$("select[name='model']").append("<option value='"+value.id+"'>"+value.name);
				}
			});
		});
	}
	function CheckForm(){
		var higher = $("input[name='higher']").val();
		var apply_username = $("input[name='apply_username']").val();
		var back_weekly = $("input[name='back_weekly']").val();
		
		if( apply_username == '' ){
			alert("请填写申请人！");return false;
		}
		if( higher == '' ){
			alert("请填写直属销售姓名！");return false;
		}
		//检测申请时间
		var apply_date = $("input[name='apply_date']").val();
		var back_time = $("input[name='back_time']").val();
		if(apply_date == ''){
			alert("请选择申请时间！");return false;
		}
		var time = parseInt(apply_date.replace(/-/g, ""));
		var backtime = parseInt(back_time.replace(/-/g, ""));//归还时间
		var date = new Date();
		var month = date.getMonth()+1;
		var dat = date.getDate();
		
		if(month < 10){
			month = "0"+month;
		}
		if( dat < 10 ){
			dat = "0"+dat;
		}
		var today = date.getFullYear()+''+month+''+dat;
		if( time < today){
			alert("申请日期必须要大于或等于当前日期！");return false;
		}
		
		var type = $("input[name='type']:checked").val();
		if( type != 1 && type != 2){
			alert("请选择设备类型！");return false;
		}

		if(back_time == ''){
			alert("请选择归还时间！");return false;
		}
		if( backtime <= time){
			alert("归还日期必须要大于申请日期！");return false;
		}
		
	}
</script>
</html>